package com.foreknow.demo2;

import jdk.internal.util.xml.impl.Input;

import java.util.Scanner;

public class LoopWork2 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
//        1.随机整数每一位之和
        System.out.println("请任意输入一个五位整数");
        int num = input.nextInt();
        int sum = 0;
        while(num > 0){
            sum = sum + num%10;
            num = num /10;
        }
        System.out.println(sum);

        System.out.println("请输入您本次行驶的公里数");
        double distance = input.nextDouble();
        double sumMoney = 0;
        if (distance <= 2) {
            sumMoney = 8;
        }else if (distance > 2) {
            sumMoney = 8 + (distance -2)*4.5;
        }
        System.out.println("您本次一共行驶"+distance+"公里,"+"金额为" + sumMoney);

        System.out.println("请输入一个年份");
        int yearSpecial = input.nextInt();
        if ((yearSpecial % 4 == 0 && yearSpecial % 100 != 0) || yearSpecial % 400 == 0){
            System.out.println("是闰年");
        }else {
            System.out.println("不是闰年");
        }
        System.out.println("请输入月份");
        int month = input.nextInt();
        if (month >= 1 && month <= 3){
            System.out.println("春");
        }else if (month >= 4 && month <= 6) {
            System.out.println("夏");
        }else if (month >= 7 && month <= 9) {
            System.out.println("秋");
        }else if (month >= 10 && month <= 12){
            System.out.println("冬");
        }
        System.out.println("请输入用电量");
        double eletricNum = input.nextInt();
        double eletricMoney = 0.0;
        double baseMoney = 64.5;
        if (eletricNum <= 150) {
            eletricMoney = eletricNum * 0.43;
        }else if (eletricNum >= 151 && eletricNum <=400){
            eletricMoney = (eletricNum - 150) * 0.45 + baseMoney;
        }else if(eletricNum >= 401){
            eletricMoney = (eletricNum - 150) * 0.45 + baseMoney + (eletricNum - 400) * 0.52;
        }
        System.out.println("本次用电量为" + eletricNum + "金额为" + eletricMoney);

        System.out.println("请输入消费金额和积分");
        double userSal = input.nextDouble();
        int userPoints = input.nextInt();
        if (userPoints <= 2000){
            userSal *= 0.9;
        }else if (userPoints <= 4000 && userPoints > 2000) {
            userSal *= 0.8;
        }else if (userPoints <= 8000 && userPoints > 4000) {
            userSal *= 0.75;
        }else if (userPoints > 8000) {
            userSal *= 0.7;
        }
        System.out.println("本次应缴金额" +userSal);
        for (int i = 1;i <=9;i++){
            for (int j = 1; j<= i;j++){
                System.out.print(j + "*" + i + "=" + i*j + " ");
            }
            System.out.print("\n");
        }
    }
}
